package tech.aistar.service;

import com.alibaba.fastjson.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
//json
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class UserLoginServiceTest {
    @Autowired
    private IUserLoginService userLoginService;
    @Autowired
    private IUserInfoService userInfoService;

    @Test
    public void testInfo(){
        System.out.println(userLoginService.findAllInfo(1).getUserInfo());
    }

    @Test
    public void testPhone(){
        List<String> list = userInfoService.findPhones();
        list.forEach(System.out::println);
    }

    @Test
    public void testPhones(){
        List<String> phones = userInfoService.findPhones();
        for(String p:phones) {
            if (null != p && p.equals("18862635790")) {
                System.out.println("-------------------------------------------------------------------+不可以");
                return;
            }
        }
        System.out.println("可以");
    }

    @Test
    public void testJsonArray() {
        String jsonString = "{\"data\":{\"sex\":\"男\",\"address\":\"山东省-潍坊市-寒亭区\",\"birthday\":\"1981-11-30\"},\"resp\":{\"code\":0,\"desc\":\"匹配\"}}";
        try {
            JSONObject jsonObject = JSONObject.parseObject(jsonString);
            JSONObject person = jsonObject.getJSONObject("resp");
            String code = null;
            if (person != null) {
                //System.out.println(jsonArray.get(i));
                code = person.getString("code");
                System.out.println(code);
            }
            if ("0".equals(code)) {
                System.out.println(true);
                return;
            } else {
                System.out.println(false);
                return;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        //获取response的body
        //System.out.println(EntityUtils.toString(response.getEntity()));
        System.out.println(false);
    }
}
